package com.atguigu.edu.realtime.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: KeyWordUtil
 * @Description: TODO IK分词器工具类
 * @Author: zhaoxunfeng
 * @Date: 2022-08-31 17:26
 * @Version: 1.0.0
 */
public class KeyWordUtil {
    public static List<String> analyze(String text) {
        ArrayList<String> list = new ArrayList<>();
        IKSegmenter ikSegmenter = new IKSegmenter(new StringReader(text), true);
        try {
            Lexeme next = null;
            while ((next = ikSegmenter.next()) != null) {
                String keyword = next.getLexemeText();
                list.add(keyword);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    public static void main(String[] args) {
        System.out.println(analyze("Apple iPhoneXSMax (A2104) 256GB 深空灰色 移动联通电信4G手机 双卡双待").toString());
    }
}
